package com.example.mylibrary;

import static android.content.ContentValues.TAG;
import android.app.Instrumentation;
import android.util.Log;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.uiautomator.By;
import androidx.test.uiautomator.UiDevice;
import androidx.test.uiautomator.UiObject2;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class Cashbook {
    Instrumentation instrumentation=null;
    UiDevice device=null;
    @Before
    public void initInstrumentation() throws InterruptedException {
        Log.i(TAG,"连接设备");
        instrumentation=
                InstrumentationRegistry.getInstrumentation();
        device=UiDevice.getInstance(instrumentation);
        device.pressHome();
        UiObject2 icon1=device.findObject
                (By.text("CashBook"));
        icon1.click();
        Thread.sleep(3000);
    }
    //    注册
    private void Register() throws InterruptedException {
        device.findObject(By.res("com.lyc.cashbook:id/register")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/et_account")).setText("Lizeyu");
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/et_psw")).setText("1");
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/et_psw_again")).setText("1");
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/register")).click();
    }

    //    登录
    private void Login() throws InterruptedException {
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/et_account")).setText("Lizeyu");
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/et_psw")).setText("1");
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/login")).click();
    }

    //   打开关于
    @Test
    public void testAbout() throws InterruptedException {
        Register();
        Login();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:test/\"更多选项\"")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:test/\"关于\"")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/button2")).click();
        Thread.sleep(1000);
    }

    //   换背景
    @Test
    public void testBackground() throws InterruptedException {
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:test/\"更多选项\"")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/content")).click();
        Thread.sleep(1000);
    }

    //   打开/关闭音乐
    @Test
    public void testMusic() throws InterruptedException {
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:test/\"更多选项\"")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:test/\"关闭/开启音乐\"")).click();
        Thread.sleep(1000);
    }

    //   添加账单记录——支出——话费(不添加备注信息)100
    @Test
    public void testOutone() throws InterruptedException {
        device.findObject(By.res("com.lyc.cashbook:id/fb")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:test/\"支出\"")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/iv_hf")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_1")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_0")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_0")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_sure")).click();
        Thread.sleep(1000);
    }

    //   添加账单记录——支出——购物(添加备注信息)500
    @Test
    public void testOuttwo() throws InterruptedException {
        device.findObject(By.res("com.lyc.cashbook:id/fb")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:test/\"支出\"")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/iv_gw")).setText("购物");
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_5")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_0")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_0")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_sure")).click();
        Thread.sleep(1000);
    }

    //   添加账单记录——支出——吃饭(不添加备注信息)22.2
    @Test
    public void testOutthree() throws InterruptedException {
        device.findObject(By.res("com.lyc.cashbook:id/fb")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:test/\"支出\"")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/iv_cf")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_2")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_2")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_dot")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_2")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_sure")).click();
        Thread.sleep(1000);
    }

    //   添加账单记录——支出——其他(添加备注信息)11.1
    @Test
    public void testOutfour() throws InterruptedException {
        device.findObject(By.res("com.lyc.cashbook:id/fb")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:test/\"支出\"")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/ll_qt")).setText("其他");
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_1")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_1")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_dot")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_1")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_sure")).click();
        Thread.sleep(1000);
    }

    //    添加账单记录——收入——工资(不添加备注信息)10000
    @Test
    public void testInone() throws InterruptedException {
        device.findObject(By.res("com.lyc.cashbook:id/fb")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:test/\"收入\"")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/iv_gz")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_1")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_0")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_0")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_0")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_0")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_sure")).click();
        Thread.sleep(1000);
    }

    //   添加账单记录——收入——津贴(添加备注信息)500
    @Test
    public void testIntwo() throws InterruptedException {
        device.findObject(By.res("com.lyc.cashbook:id/fb")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:test/\"收入\"")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/iv_gw")).setText("津贴");
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_5")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_0")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_0")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_sure")).click();
        Thread.sleep(1000);
    }

    //    添加账单记录——收入——红包(不添加备注信息)66.66
    @Test
    public void testInthree() throws InterruptedException {
        device.findObject(By.res("com.lyc.cashbook:id/fb")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:test/\"收入\"")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/iv_sr")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_6")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_6")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_dot")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_6")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_6")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_sure")).click();
        Thread.sleep(1000);
    }

    //   添加账单记录——收入——其他(添加备注信息)50.05
    @Test
    public void testInfour() throws InterruptedException {
        device.findObject(By.res("com.lyc.cashbook:id/fb")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:test/\"收入\"")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/ll_qt")).setText("其他");
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_5")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_0")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_dot")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_5")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_sure")).click();
        Thread.sleep(1000);
    }

    //    添加账单记录——收入——工资(不添加备注信息)51，删除最后的1,金额变为5
    @Test
    public void test1() throws InterruptedException {
        device.findObject(By.res("com.lyc.cashbook:id/fb")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:test/\"收入\"")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/iv_gz")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_5")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_1")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_delete")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_sure")).click();
        Thread.sleep(1000);
    }

    //    添加账单记录——收入——其他(不输入数据，点击确定)
    @Test
    public void test2() throws InterruptedException {
        device.findObject(By.res("com.lyc.cashbook:id/fb")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:test/\"收入\"")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/ll_qt")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_sure")).click();
        Thread.sleep(1000);
    }

    //    添加账单记录——收入——工资(不添加备注信息)多位小数12.3456
    @Test
    public void test3() throws InterruptedException {
        device.findObject(By.res("com.lyc.cashbook:id/fb")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:test/\"收入\"")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/iv_gz")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_1")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_2")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_dot")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_3")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_4")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_5")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_6")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_sure")).click();
        Thread.sleep(1000);
    }

    //    添加账单记录——支出——工资(不添加备注信息)多位小数12.3456
    @Test
    public void test4() throws InterruptedException {
        device.findObject(By.res("com.lyc.cashbook:id/fb")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:test/\"支出\"")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/iv_gz")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_1")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_2")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_dot")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_3")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_4")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_5")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_6")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_sure")).click();
        Thread.sleep(1000);
    }

    //    搜索关键字
    @Test
    public void test5() throws InterruptedException {
        device.findObject(By.res("com.lyc.cashbook:id/search")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/et_search")).setText("123");
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_search")).click();
        Thread.sleep(1000);
        device.findObject(By.clazz("android.widget.ImageView")).click();
        Thread.sleep(1000);
    }

    //    跳转到图表页面
    @Test
    public void test6() throws InterruptedException {
        device.findObject(By.res("com.lyc.cashbook:id/tb")).click();
        Thread.sleep(1000);
    }

    //    跳转到我的页面
    @Test
    public void test7() throws InterruptedException {
        device.findObject(By.res("com.lyc.cashbook:id/wd")).click();
        Thread.sleep(1000);
    }
    @After
    public  void quite(){
        device.pressBack();
    }



}